package gogogo.liwushuo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import gogogo.liwushuo.R;
import gogogo.liwushuo.bean.CgLeftHeaderBean;
import gogogo.liwushuo.listener.OnItemHeaderCheckallClickListener;

/**
 * Created by Godman_Kai on 2016/7/20.
 */
public class CgLeftCheckAllAdapter_1 extends RecyclerView.Adapter<CgLeftCheckAllAdapter_1.MyHolder> {
    private Context mContext;
    private List<CgLeftHeaderBean.DataBean.ColumnsBean> mDatas;

    public CgLeftCheckAllAdapter_1(Context context, List<CgLeftHeaderBean.DataBean.ColumnsBean> datas) {
        this.mContext = context;
        this.mDatas = datas;
    }
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_cgleft_checkall_1, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyHolder holder, final int position) {
        Picasso.with(mContext).load(mDatas.get(position).getBanner_image_url()).into(holder.iv);
        holder.tv1.setText(mDatas.get(position).getTitle());
        holder.tv2.setText(mDatas.get(position).getSubtitle());
        holder.tv3.setText(mDatas.get(position).getAuthor());
        if (mListener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.OnItemHeaderCheckallClick(position,mDatas);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        private ImageView iv;
        private TextView tv1,tv2,tv3;
        public MyHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.iv_cgleft_checkall_1);
            tv1 = (TextView) itemView.findViewById(R.id.tv_cgleft_checkall_1_title);
            tv2 = (TextView) itemView.findViewById(R.id.tv_cgleft_checkall_1_subtitle);
            tv3 = (TextView) itemView.findViewById(R.id.tv_cgleft_checkall_1_name);
        }
    }
    private OnItemHeaderCheckallClickListener mListener;
    public void setOnItemHeaderCheckallClickListener(OnItemHeaderCheckallClickListener listener){
        this.mListener = listener;
    }

}
